<template>
	<Container>
		<view class="header">
			<image class="comparedArticle" :src="assignment.comparedArticle.imageUrl" mode="widthFix"></image>
			<AudioIcon @iconTap="iconTap" :questionPress="questionPress" />
		</view>
		<Question :question="assignment.questionName" />
		<view class="articleBox">
			<view :class="{ hidden: chooses[index] === 'hidden' }" @tap="tap(item, index)" class="articles" v-for="(item, index) in assignment.optionArticles" :key="index">
				<view class="box" :class="{ success: chooses[index] === 'select' || chooses[index] === 'success', error: chooses[index] === 'error' }">
					<image class="item" mode="aspectFit" :src="item.imageUrl"></image>
					<SuccessIcon v-if="chooses[index] === 'success'" />
				</view>
			</view>
		</view>
	</Container>
</template>

<script>
import { mixins } from '../../../common/mixins/assignmentDefault.js'
import AudioIcon from '../audioIcon.vue'
import Question from '../questionName.vue'
import Container from '../container.vue'
import SuccessIcon from '../successIcon.vue'
export default {
	mixins: [mixins],
	components: { AudioIcon, Question, Container, SuccessIcon },
	methods: {
		tap: function(item, index) {
			this.touchAudio()
			if (this.isComplete) return
			if (this.chooses[index] === 'select') {
				this.optionStatus('', index)
			} else {
				this.optionStatus('select', index)
				if (this.choosesKey.indexOf(index) < 0) this.choosesKey.push(index)
			}
			if (this.choosesKey.length === 3) {
				this.isComplete = true
				const bool = this.choosesKey.every(item => {
					return this.assignment.optionArticles[item].isMatched
				})
				if (bool) {
					this.choosesKey.map(item => {
						this.optionStatus('success', item)
					})
					this.assignment.optionArticles.map((item, current) => {
						if (this.choosesKey.indexOf(current) < 0) {
							this.optionStatus('hidden', current)
						}
					})
					this.$parent.next({
						isSure: true
					})
				} else {
					this.choosesKey.map(item => {
						this.optionStatus('error', item)
					})
					this.$parent.next()
				}
			}
		}
	}
}
</script>

<style scoped lang="stylus">
.header
	height 45vh
	width 100%
	border-radius 70rpx
	border 12rpx solid #FCC77D
	box-sizing border-box
	margin 5vh 0
	background #FCC77D
	display flex
	align-items center
	justify-content center
	position relative
	.comparedArticle
		width 40%
		height auto
.articleBox
	width 100%
	height 40vh
	display flex
	flex-wrap wrap
	justify-content center
	align-items center
	.articles
		width 25%
		height 220rpx
		transition all 0.5s
		color #FFC268
		justify-content center
		align-items center
		display flex
		position relative
		.box
			width 85%
			height 85%
			transition all 0.5s
			border 8rpx solid #FCC77D
			box-sizing border-box
			border-radius 30rpx
			justify-content center
			align-items center
			display flex
			.item
				height 80%
				width 70%
				filter drop-shadow(2px 0px #fff) drop-shadow(-2px 0px #fff) drop-shadow(0px -2px #fff) drop-shadow(0px 2px #fff) drop-shadow(2px 2px 1px #0000004a)
</style>
